package org.example.service.impl;

import com.alipay.api.domain.UserIdentity;
import org.example.domain.entity.UserAddr;
import org.example.mapper.UserAddrMapper;
import org.example.service.IUserAddrService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

/*
szy

*/
@Service
public class UserAddrServiceImpl implements IUserAddrService {

    @Resource
    private UserAddrMapper userAddrMapper;

    @Override
    public void addAddr(UserAddr userAddr) {
        //查全部
        List<UserAddr> userAddrs = userAddrMapper.selectByUserId(userAddr.getUserId(),2);
        if (userAddrs.size()!=0){
            userAddr.setCommonAddr(0);
        }
        else {
            userAddr.setCommonAddr(1);
        }
        userAddr.setCreateTime(new Date());
        userAddr.setUpdateTime(new Date());
        userAddrMapper.insert(userAddr);
    }

    @Override
    public List<UserAddr> selectById(Integer userId) {
        //查非默认
        List<UserAddr> list = userAddrMapper.selectByUserId(userId,1);
        return list;
    }

    @Override
    public UserAddr selectByOneId(Integer id) {
        UserAddr userAddr = userAddrMapper.selectByOneId(id);
        return userAddr;
    }

    @Override
    public Integer deleteById(Integer addrId) {
        return userAddrMapper.deleteById(addrId);
    }
}
